#ifndef __COMMAND_H__
#define __COMMAND_H__
#include <iostream>
#include <string>

class Tv{
public:
    void OnAction(){
        std::cout << "电视开机..." << std::endl;
    }

    void OffAction(){
        std::cout << "电视关机..." << std::endl;
    }

};

class Command{
public:
    virtual ~Command(){}
    virtual void excute() = 0;
};

class OnCommand : public Command{
public:
    OnCommand(Tv* tv):m_tv(tv){}
    virtual void excute(){
        if(m_tv)
            m_tv->OnAction();
    }
private:
    Tv* m_tv;
};

class OffCommand : public Command{
public:
    OffCommand(Tv* tv):m_tv(tv){}
    virtual void excute(){
        if(m_tv)
            m_tv->OffAction();
    }
private:
    Tv* m_tv;
};

class Invoke{
public:
    void setCommand(Command* command){
        m_command = command;
    }

    void excute(){
        if(m_command)
            m_command->excute();
    }
private:
    Command* m_command;
};


#endif